home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)Z / (A)Z8.ADF / PeliHacks / benchquake.c < prev    next >
C/C++ Source or Header  |  1988-07-25  |  4KB  |  216 lines

  1. /* BenchQuake, by Oren Peli. Copyright (c) 1988 BazboSoft! */
  2.  
  3. /* Should be called automatically from the 'Startup-Sequence' of all California
  4.     residents!  */
  5.  
  6. #include <exec/ports.h>
  7. #include <devices/inputevent.h>
  8. #include <devices/input.h>
  9.  
  10. extern long OpenDevice();
  11.  
  12. extern struct MsgPort *CreatePort();
  13. extern struct IOStdReq *CreateStdIO();
  14.  
  15. struct MsgPort *port = NULL;
  16. struct IOStdReq *req;
  17.  
  18. long errdev = 0;
  19.  
  20. struct InputEvent ie;
  21.  
  22. void *OpenLibrary() , *IntuitionBase , *GfxBase;
  23.  
  24. struct Screen *OpenWorkBench();
  25.  
  26. main()
  27. {
  28.     REGISTER WORD q , i , x , y;
  29.  
  30.     REGISTER struct RastPort *rp;
  31.     REGISTER struct ViewPort *vp;
  32.  
  33.     REGISTER struct Screen *scr;
  34.  
  35.     IntuitionBase = OpenLibrary("intuition.library" , 33L);
  36.     GfxBase = OpenLibrary("graphics.library" , 33L);
  37.  
  38.     if (NOT IntuitionBase || NOT GfxBase)
  39.         bye();
  40.  
  41.     if (NOT (port = CreatePort(0L , 0L) ) )
  42.         bye();
  43.  
  44.     if (NOT (req = CreateStdIO(port) ) )
  45.         bye();
  46.  
  47.     if (errdev = OpenDevice("input.device" , 0L , req , 0L) )
  48.         bye();
  49.  
  50.     puts("BenchQuake, by Oren Peli. Copyright (c) 1988 BazboSoft!");
  51.  
  52.     scr = OpenWorkBench();
  53.  
  54.     vp = &scr->ViewPort;
  55.     rp = &scr->RastPort;
  56.  
  57.     x = vp->DxOffset;
  58.     y = vp->DyOffset;
  59.  
  60.     for (i = 0 ; i <= random(200) + 50 ; i++)
  61.         RangeRand( (LONG) random(27441) );
  62.  
  63.     req->io_Command = IND_WRITEEVENT;
  64.     req->io_Flags = 0;
  65.     req->io_Length = (long) sizeof(struct InputEvent);
  66.     req->io_Data = (void *) &ie;
  67.  
  68.     ie.ie_NextEvent = NULL;
  69.     ie.ie_Class = IECLASS_RAWMOUSE;
  70.     ie.ie_TimeStamp.tv_secs = 0;
  71.     ie.ie_TimeStamp.tv_micro = 0;
  72.     ie.ie_Code = NULL;
  73.     ie.ie_Qualifier = IEQUALIFIER_RELATIVEMOUSE;
  74.  
  75.     for (q = 1 ; q != 45 ; q++)
  76.     {
  77.         for (i = 0 ; i != 25 ; i++)
  78.         {
  79.             vp->DxOffset = RangeRand( (LONG) q * 2L) - q;
  80.             vp->DyOffset = RangeRand( (LONG) q) - (q / 2);
  81.  
  82.             MakeScreen(scr);
  83.  
  84.             RethinkDisplay();
  85.  
  86.             ShiverPointer(q);
  87.         }
  88.  
  89.         ScrambleRP(rp , scr , q);
  90.         ScrambleRP(rp , scr , q);
  91.         ScrambleRP(rp , scr , q);
  92.         ScrambleRP(rp , scr , q);
  93.         ScrambleRP(rp , scr , q);
  94.     }
  95.  
  96.     for ( ; q != 0 ; q--)
  97.     {
  98.         for (i = 0 ; i != 20 ; i++)
  99.         {
  100.             vp->DxOffset = RangeRand( (LONG) q * 2L) - q;
  101.             vp->DyOffset = RangeRand( (LONG) q) - (q / 2);
  102.  
  103.             MakeScreen(scr);
  104.  
  105.             RethinkDisplay();
  106.  
  107.             ShiverPointer(q);
  108.         }
  109.  
  110.         ScrambleRP(rp , scr , q);
  111.     }
  112.  
  113.     vp->DxOffset = x;
  114.     vp->DyOffset = y;
  115.  
  116.     MakeScreen(scr);
  117.  
  118.     RethinkDisplay();
  119.  
  120.     bye();
  121. }
  122.  
  123. ShiverPointer(q)
  124. REGISTER WORD q;
  125. {
  126.     if (q < 1)
  127.         q = 1;
  128.  
  129.     ie.ie_X = 2 * (RangeRand( (LONG) q) - (q / 2) );
  130.     ie.ie_Y = 2 * (RangeRand( (LONG) q) - (q / 2) );
  131.  
  132.     DoIO(req);
  133. }
  134.  
  135. ScrambleRP(rp , scr , q)
  136. REGISTER WORD q;
  137. REGISTER struct Screen *scr;
  138. REGISTER struct RastPort *rp;
  139. {
  140.     REGISTER WORD srcx , srcy , width , height , destx , desty;
  141.  
  142.     if (q < 5)
  143.         return;
  144.  
  145.     width = RangeRand( (LONG) q * 2L);
  146.     height = RangeRand( (LONG) q);
  147.  
  148.     if (width < 1)
  149.         width = 1;
  150.  
  151.     if (height < 1)
  152.         height = 1;
  153.  
  154.     srcx = RangeRand( (LONG) scr->Width - width);
  155.     srcy = RangeRand( (LONG) scr->Height - height);
  156.  
  157.     destx = srcx + RangeRand( (LONG) q * 2L) - q;
  158.     desty = srcy + RangeRand( (LONG) q) - (q / 2);
  159.  
  160.     if (srcx < 0)
  161.         srcx = 0;
  162.  
  163.     if (srcy < 0)
  164.         srcy = 0;
  165.  
  166.     if (destx < 0)
  167.         destx = 0;
  168.  
  169.     if (desty < 0)
  170.         desty = 0;
  171.  
  172.     if (destx + width >= scr->Width)
  173.         destx = scr->Width - width - 1;
  174.  
  175.     if (desty + height >= scr->Height)
  176.         desty = scr->Height - height - 1;
  177.  
  178.     ClipBlit(rp , (LONG) srcx , (LONG) srcy , rp , (LONG) destx , (LONG) desty ,
  179.                                                 (LONG) width , (LONG) height , 0xC0L);
  180. }
  181.  
  182. random(max)
  183. REGISTER WORD max;
  184. {
  185.     static ULONG num;
  186.     ULONG sec , mic;
  187.  
  188.     CurrentTime(&sec , &mic);
  189.  
  190.     num *= sec;
  191.     num += mic;
  192.  
  193.     while (num > 32000)
  194.         num = num >> 1;
  195.  
  196.     return( (WORD) (num % (ULONG) max) );
  197. }
  198.  
  199. bye()
  200. {
  201.     if (NOT errdev)
  202.         CloseDevice(req);
  203.  
  204.     if (req)
  205.         DeleteStdIO(req);
  206.  
  207.     if (port)
  208.         DeletePort(port);
  209.  
  210.     if (GfxBase)
  211.         CloseLibrary(GfxBase);
  212.  
  213.     if (IntuitionBase)
  214.         CloseLibrary(IntuitionBase);
  215. }
  216.